#!/bin/bash

infos_users(){
cat /etc/passwd | cut -d: -f 1-7 | grep "[5-9][0-9][0-9]" | grep "/home" | cut -d: -f1-7 > /tmp_users

while IFS= read -r LINE

do
   echo "-------------------------------------------------------------------"
   echo ""
   gawk -F":" '{print "Le Nom de l utilisateur est :" $1}' <<< "$LINE"
   gawk -F":" '{print "UID :" $3}' <<< "$LINE"
   gawk -F":" '{print "GID :" $4}' <<< "$LINE"
   gawk -F":" '{print "Description complete :" $5}' <<< "$LINE"
   gawk -F":" '{print "Home Directory :" $6}' <<< "$LINE"
   gawk -F":" '{print "Shell par défaut :" $7}' <<< "$LINE"
   echo ""
done < /tmp_users

}

open_sessions(){
echo "La liste des utilisateurs connectés :"
#users
w

}

simple_system_users(){
echo "La liste des simples utilisateurs :"
echo "------"
cat /etc/passwd | cut -d: -f 1-7 | grep "[5-9][0-9][0-9]" | grep "/home"| cut -d: -f1
echo "------"
echo "la liste des utilisateurs systéme :"
cat /etc/passwd | cut -d: -f 1,3 > /tmp_usr
while IFS= read -r LINE
do
   gawk -F":" '{if($2 < 500) print $1}' <<< "$LINE"
done < /tmp_usr
}

clear
echo "-------------------------------------"
echo ""
echo "[1] . Fournir les infos sur tous les utilisateurs "
echo "[2] . Lister les sessions ouverts "
echo "[3] . Listes les utilisateurs simple/Systeme "
echo ""
echo "---------------------------------------"

echo "Saisir :"
read CHOIX

case $CHOIX in
1)     
    infos_users;;
2) 
    open_sessions;;
3) 
    simple_system_users;;
*)
    echo "Choix [1-3]"
esac






#for i in /tmp_users ; do
#echo $i 
#done

